This script will read in data from research by Alexandar et al and create graphics with a unique theme

## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:flextable':
## 
##     style
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout

Figure 1

Because figure 1 has 32 rows, I recommend shortening the amount visible. In the same vein, the column “docket_text” is also quite long, so I discarded everything after the 40th character and added an ellipsis at the end of each row.

# read in figure 1 data set
figure_1 <- read_csv(paste0(data_folder, '/figure_1.csv'))
## Parsed with column specification:
## cols(
##   case_number = col_character(),
##   activity_date = col_character(),
##   activity_number = col_integer(),
##   docket_text = col_character()
## )
## Warning in rbind(names(probs), probs_f): number of columns of result is not
## a multiple of vector length (arg 2)
## Warning: 1 parsing failure.
## row # A tibble: 1 x 5 col     row col   expected  actual    file                                   expected   <int> <chr> <chr>     <chr>     <chr>                                  actual 1 52802 <NA>  4 columns 3 columns '../data/Alexander_et_al/figure_1.csv' file # A tibble: 1 x 5
# subset data by selecting all the rows in which are not NA in column 'case_number'
figure_1 <- figure_1[!is.na(figure_1$case_number),]

# figure 1 in the paper has 3 more columns than what is available in the data
# shorten the last column and add '...' to not blow up the table
figure_1$docket_text <- paste0(substr(figure_1$docket_text, 1, 40), '...')

# create a dummy row for the table 
dummy_row <- c('...', '...', '...', '...')
last_row <- figure_1[nrow(figure_1),]

# combine with a subsetted version of figure 1 for the table appearance
figure_1_sub <- figure_1[1:10, ]
figure_1_table <- rbind(figure_1_sub, 
                        dummy_row,
                        last_row)

# generate a latex table as suggested in the paper using kable
kable(figure_1_table, caption = 'Figure 1') %>% 
  kable_styling(bootstrap_options = c("condensed", 'striped'),
                full_width = TRUE)
Figure 1
case_number activity_date activity_number docket_text
1:10-cv-00002-ODE 1/4/2010 1 NOTICE OF REMOVAL with COMPLAINT, filed …
1:10-cv-00002-ODE 1/5/2010 2 Unopposed MOTION for Extension of Time t…
1:10-cv-00002-ODE 1/5/2010 3 ORDER granting 2 Motion for Extension of…
1:10-cv-00002-ODE 1/29/2010 4 ANSWER to 1 NOTICE OF REMOVAL with Compl…
1:10-cv-00002-ODE 1/29/2010 5 Certificate of Interested Persons by Chi…
1:10-cv-00002-ODE 2/2/2010 6 Guidelines for Discovery and Motion Prac…
1:10-cv-00002-ODE 2/23/2010 7 Joint PRELIMINARY REPORT AND DISCOVERY P…
1:10-cv-00002-ODE 2/27/2010 8 Initial Disclosures by Emmanuel Nketop.(…
1:10-cv-00002-ODE 3/2/2010 9 Initial Disclosures by Children’s Health…
1:10-cv-00002-ODE 3/5/2010 10 Certificate of Interested Persons by Emm…
1:10-cv-00002-ODE 10/13/2010 NA Civil Case Terminated. Magistrate Judge …

Figure 6

# read in figure 6 data set 
figure_6 <- read.xlsx(paste0(data_folder, '/figure_6.xlsx'), sheetName = 1)

# remove * from pair_order_text and docket_text to mimic the text in the paper 
figure_6$paired_order_text <- gsub('*', '', figure_6$paired_order_text, fixed = TRUE)
figure_6$docket_text <- gsub('*', '', figure_6$docket_text, fixed = TRUE)


# generate a latex table 
kable(figure_6, caption = 'Figure 6') %>% 
  kable_styling(bootstrap_options = c("condensed", 'striped'),
                full_width = TRUE)
Figure 6
case_number docket_text paired_order_text who_filed order_adopted case_ending
1:10-cv-00007-JEC FINAL REPORT AND RECOMMENDATION recommending GRANTING 22 MOTION for Summary Judgment as to all of Plaintiff’s claims. Signed by Magistrate Judge Gerrilyn G. Brill on 06/14/11. (Attachments: # 1 Order for Service)(fap) (Entered: 06/15/2011) ORDER regarding Magistrate Judge’s Final Report and Recommendation. IT IS HEREBY ORDERED that the Court ADOPTS the Magistrate Judge’s Final Report and Recommendation 28 GRANTING defendants’ Motion for Summary Judgment as to all of plaintiff’s claim 22 . The Clerk is directed to close this action. Signed by Judge Julie E. Carnes on 7/5/11. (cem) (Entered: 07/06/2011) defendant adopt TRUE
1:10-cv-00383-ODE REPORT AND RECOMMENDATION that Defendant’s 42 MOTION for Summary Judgment be GRANTED IN PART AND DENIED IN PART. Specifically, the undersigned RECOMMENDS that the motion for summary judgment be DENIED with respect to Plaintiffs’ Title VII claims, DENIED with respect to Plaintiffs’ S. 1981 claims, and GRANTED with respect to Plaintiff Lewis, Power, and Johnson’s claims under the Equal Protection Clause. Signed by Magistrate Judge Alan J. Baverman on 1/31/2012. (rej) (Entered: 02/01/2012) ORDER that City of Kennesaw’s Objections are 56 SUSTAINED and the 55 Report and Recommendation is ADOPTED IN PART AND REJECTED IN PART. The City of Kennesaw’s 42 Motion for Summary Judgment is GRANTED in accordance with Federal Rule of Civil Procedure 56(a) because Plaintiffs have failed to establish a prima facie case of discrimination. Signed by Judge Orinda D. Evans on 3/30/2012. (anc) (Entered: 03/30/2012) defendant partial FALSE

Figure 4

# read in figure 4 and 7 data set
figure_4_7 <- read.xlsx(paste0(data_folder, '/figure_4_7.xlsx'), sheetName = 1)

# split data up into figure_4 and figure_7
figure_4 <- figure_4_7[,1:2]
rm(figure_4_7)

# recode names of columns
names(figure_4) <- c('variable', 'percentage')

# convert percents to percentage form round 
figure_4$percentage <- round((figure_4$percentage*100))

# create two separate data sets for figure_4 for the two pie charts in the paper
figure_4_1 <- figure_4[grepl('Exemption|Color|Race|National|Religion|Sex|Retaliation', figure_4$variable),]
figure_4_2 <- figure_4[grepl('Indian|Middle|Hispanic|Asian|African|Native', figure_4$variable),]
rm(figure_4)

# # reorder factors 
# figure_4_1$variable <- factor(figure_4_1$variable, levels = c('Retaliation', 'Exemption', 'Color', 'Race', 'National origin', 'Religion', 'Sex'))
# figure_4_1$variable <- as.character(figure_4_1$variable)

# get font object for plot
f <- list(
     size = 13,
     color = "#A9A9A9"
    )

title_f <- list(
     size = 16,
     color = "black"
    )


# get a gray scale color vector for the pie chart
colors <- gray.colors(length(unique(figure_4_1$variable)))


# use plotly's R pakage to create tow side by side pie charts
plot_ly(figure_4_1 ,labels = ~variable, values = ~percentage,
                            type ='pie',
                            hole = 0,
                            text= ~variable,
                            textposition = 'outside',
                            outsidetextfont = f,
        height = 800, width = 1200,
        domain = list(x = c(0, 0.3), y = c(0, 1)),
        marker = list(colors = colors,
                      line = list(color = '#FFFFFF', width = 0.5)))  %>%
  add_pie(data = figure_4_2, labels = ~variable, values = ~percentage,
          domain = list(x = c(0.5, 0.8), y = c(0, 1))) %>%
      
      config(displayModeBar = F) %>%
      
      layout(title = '' , font = title_f, showlegend = F,
             annotations = list(
               showarrow = FALSE,
               text = ''), 
             xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
             yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE), 
             margin = list(l = 50, r = 50, b = 50, t = 50)) 

Figures 7

# read in figure 4 and 7 data set
figure_4_7 <- read.xlsx(paste0(data_folder, '/figure_4_7.xlsx'), sheetName = 1)

# split data up into figure_7
figure_7 <- figure_4_7[,3:4]
rm(figure_4_7)

# recode names of columns
names(figure_7) <- c('variable', 'percentage')

# convert percents to percentage form and round 
figure_7$percentage <- round((figure_7$percentage*100))

# remove NAs
figure_7 <- figure_7[complete.cases(figure_7),]

# get a gray scale color vector 
colors <- gray.colors(length(unique(figure_7$variable)))

# plot
plot_ly(figure_7 ,labels = ~variable, values = ~percentage,
                            type ='pie',
                            hole = 0,
                            text= ~variable,
                            textposition = 'outside',
                            outsidetextfont = f,
        domain = list(x = c(0, 1), y = c(0, 0.8)),
        marker = list(colors = colors,
                      line = list(color = '#FFFFFF', width = 0.5)))  %>%
      config(displayModeBar = F) %>%
      
      layout(title ='' , font = title_f, showlegend = F,
             annotations = list(
               showarrow = FALSE,
               text = ''), 
             xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
             yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))